package com.yxb.orders.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.orders.domain.MyOrders;
import com.yxb.orders.service.IMyOrdersService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 我的接单Controller
 * 
 * @author 林德炫
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/orders/orders")
public class MyOrdersController extends BaseController
{
    @Autowired
    private IMyOrdersService myOrdersService;

    /**
     * 查询我的接单列表
     */
    @PreAuthorize("@ss.hasPermi('orders:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyOrders myOrders)
    {
        startPage();
        List<MyOrders> list = myOrdersService.selectMyOrdersList(myOrders);
        return getDataTable(list);
    }

    /**
     * 导出我的接单列表
     */
    @PreAuthorize("@ss.hasPermi('orders:orders:export')")
    @Log(title = "我的接单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MyOrders myOrders)
    {
        List<MyOrders> list = myOrdersService.selectMyOrdersList(myOrders);
        ExcelUtil<MyOrders> util = new ExcelUtil<MyOrders>(MyOrders.class);
        util.exportExcel(response, list, "我的接单数据");
    }

    /**
     * 获取我的接单详细信息
     */
    @PreAuthorize("@ss.hasPermi('orders:orders:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
//        System.out.println("111111111111111111111获取我的接单详细信息:"+myOrdersService.selectMyOrdersByOrderId(orderId));
        return success(myOrdersService.selectMyOrdersByOrderId(orderId));
    }

    //
    @GetMapping(value = "listSquareById/{userId}")
    public AjaxResult listSquareById(@PathVariable("userId") Long userId)
    {
        return success(myOrdersService.listSquareById(userId));
    }

    /**
     * 新增我的接单
     */
    @PreAuthorize("@ss.hasPermi('orders:orders:add')")
    @Log(title = "我的接单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyOrders myOrders)
    {
        return toAjax(myOrdersService.insertMyOrders(myOrders));
    }

    /**
     * 修改我的接单
     */
    @PreAuthorize("@ss.hasPermi('orders:orders:edit')")
    @Log(title = "我的接单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyOrders myOrders)
    {
        return toAjax(myOrdersService.updateMyOrders(myOrders));
    }

    /**
     * 删除我的接单
     */
    @PreAuthorize("@ss.hasPermi('orders:orders:remove')")
    @Log(title = "我的接单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(myOrdersService.deleteMyOrdersByOrderIds(orderIds));
    }
}
